package com.ruoyi.common.core.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.slf4j.MDC;

/**
 * Copyright (c) 2024, gitee
 * All rights reserved.
 *
 * @author qiupt@gitee.com
 * @description 配置OpenFeign透传traceId
 * @date 2024/10/22 16:19
 **/
@Component
@Slf4j
public class OpenFeignRequestInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        String traceId = MDC.get(TraceIdFilter.TRACE_ID);
        requestTemplate.header(TraceIdFilter.TRACE_ID, traceId);
    }
}
